<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Log {
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	protected $ci;
	const adminRouter=[''];
	public function __construct()
	{
		$this->ci =& get_instance();
	}
	public function addLog()
	{
		if(explode('/',$_SERVER['REQUEST_URI'])[1]=='admin')
		{
			if($this->ci->input->method()=='post') $input=$this->ci->input->post();
			else $input=$this->ci->input->get();
			$user_id=$this->ci->session->userdata('admin')==''?'':$this->ci->session->userdata('admin')->id;
			$log = [
				'user_id' => $user_id,
				'path'    => $_SERVER['REQUEST_URI'],
				'method'  => $this->ci->input->method(),
				'ip'      => $this->ci->input->ip_address(),
				'input'   => json_encode($input),
			];
			$this->ci->db->insert('admin_operation_log',$log);
		}
	}
}
